import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo {
    public static void main(String[] args) {
        Property p1 = new Property("叫了个鸡", 1000, 500, 2);
        Property p2 = new Property("张三丰饺子馆", 2300, 1500, 3);
        Property p3 = new Property("永和大王", 580, 3000, 1);
        Property p4 = new Property("肯德基", 6000, 200, 4);
        List<Property> properties = Arrays.asList(p1, p2, p3, p4);
        // Stream操作:sorted/map/filter
        String name = properties.stream()
                .sorted(Comparator.comparingInt(x -> x.distance))
                .findFirst()
                .get().name;
        System.out.println("距离我最近的店铺是:" + name);
        long count = properties.stream()
                .filter(p -> p.sales > 1000)
                .count();
        Stream<String> stringStream = properties.stream()
                .map(p -> p.name);
        //flatMap
        List<List<String>> lists = new ArrayList<>();
        lists.add(Arrays.asList("apple", "click"));
        lists.add(Arrays.asList("boss", "dig", "qq", "vivo"));
        lists.add(Arrays.asList("c#", "biezhi"));

        long count1 = lists.stream()
                .flatMap(Collection::stream)
                .filter(str -> str.length() > 2)
                .count();
        System.out.println(count1);
        List<String> names = properties.stream()
                .map(p -> p.name)
                .collect(Collectors.toList());
        names.stream()
                .forEach(System.out::println);
    }//
}
